<template>
  <div>
    <table>
<!--      <router-link>添加商品</router-link>-->
      <tr>
        <td>商品名称</td>
        <td>商品价格</td>
        <td>商品图片</td>
        <td>操作</td>
      </tr>
      <tr v-for="i in shop">
        <td>{{ i.name }}</td>
        <td>{{ i.price }}</td>
        <td><img :src="'http://127.0.0.1:8000'+i.pic" alt="" width="100px"></td>
        <td>
          <button @click="del(i.id)">删除</button>
        </td>
      </tr>

    </table>

  </div>
</template>

<script>
export default {
  name: "manage",
  data() {
    return {
      shop: []
    }
  },
  methods: {
    get_shop() {
      this.$axios.get('shop/')
        .then(res => {
          this.shop = res.data.list
        })
    },
    del(i) {
      this.$axios.delete('shop/?id=' + i)
        .then(res => {
          if (res.data.code == 200) {
            alert('删除成功')
            this.get_shop()
          } else {
            alert('删除失败')
          }
        })
    }

  },
  mounted() {
    this.get_shop()
  }
}
</script>

<style scoped>

</style>
